﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DeviceEntity;

namespace Test
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        //PLC参数
        DeviceEntity.Model.DeviceConfigModel plcConfig = null;
        //PLC操作类
        DeviceEntity.Device.Plc.BLL.IPlcBLL plcBLL = null;
        //PLC调试页面
        DeviceEntity.Device.Plc.View.PlcDebugView plcView = null;
        public MainWindow()
        {
            InitializeComponent();
            InitPlc();
        }

        public void InitPlc()
        {
            //设置PLC配置参数
            plcConfig = DeviceEntity.BLL.DeviceBLL.GetPlcModel(DeviceEntity.Model.TypeModel.Type.PLC_Omron_NJNX, "PLC1", "192.168.0.1:41");
            //PLC操作类
            plcBLL = DeviceEntity.BLL.DeviceBLL.GetPlcBLL(plcConfig);
            //PLC调试页面
            plcView = new DeviceEntity.Device.Plc.View.PlcDebugView(plcConfig);
            TabItemTemp.Content = plcView;
        }

        public async void PlcDemo()
        {
            //参数
            DeviceEntity.Device.Plc.Model.PlcParaModel plcParameter = new DeviceEntity.Device.Plc.Model.PlcParaModel();
            plcParameter.addr = "name";
            //调用PLC
            await plcBLL.Read(plcParameter);
            //PLC日志
            var log = plcParameter.logs;
            //判断结果
            if (plcParameter.result == true)
            {
                object result = plcParameter.value;
            }
            else
            {
                string err = plcParameter.errMsg;
            }
        }
    }
}
